/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef LIB2D_GUI_LISTBOX_H
#define LIB2D_GUI_LISTBOX_H

#include "Object.h"
#include "ScrollBar.h"

namespace liba
{
namespace lib2d
{
namespace gui
{
class ListBox;

namespace listbox
{
class Item : public Button//Object
{
	ListBox * list_box;
public:
	explicit Item( ListBox * parent );
	virtual ~Item();
	void adjust_position( double pos )
	{
		window_rect.y += pos;
	}
	double get_height()const
	{
		return 12;
	}
};
}

class ListBox : public Object
{
	class SimpleContainer : public Object
	{
		ListBox * list_box;
	public:
		SimpleContainer( ListBox * obj )
		:	Object( 0 ),
			list_box( list_box )
		{}
	};
public:
	ListBox( Object * parent );
	virtual ~ListBox();	

	virtual void on_button_down( const Vector2 & point, const Atom & button_name );
	virtual void on_button_up( const Vector2 & point, const Atom & button_name );
	virtual void on_mouse_move( const Vector2 & point );
	virtual void on_mouse_out();

	void insert( listbox::Item * item );
	void erase( listbox::Item * item );

	Object * get_container()const
	{
		return container;
	}
	double get_position()const
	{
		return scroll_bar->get_position();
	}

private:
	double length;

	AutoPtr< ScrollBar > scroll_bar;
	AutoPtr< SimpleContainer > container;

	void adjust_scroll_bar();
};

} //namespace gui
} //namespace lib2d
} //namespace liba

using namespace liba;

#endif //LIB2D_GUI_LISTBOX_H

